﻿#ifndef PIXELFORMATCOVERT_H
#define PIXELFORMATCOVERT_H


#include <QSize>
#include <QImage>
//#include <QVideoFrame>

extern "C" {
//#include "libswresample/swresample.h"
//#include "libswscale/swscale.h"
#include "libavutil/pixfmt.h"
}

#include "../Camera_global.h"

namespace Qly {

/**
 * @brief toAVPixelFormat 将 QImage 的 format 转换为 ffmpeg 的 format
 * @param format
 * @return
 */
CAMERA_EXPORT enum AVPixelFormat  toAVPixelFormat(QImage::Format format);

CAMERA_EXPORT bool RGBtoRGB888(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool RGBtoRGB32(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
/**
 * @brief YUV422toRGB888
 * @param pData
 * @param format  AV_PIX_FMT_YUYV422
 *                AV_PIX_FMT_UYVY422
 * @param size
 * @param image
 * @return
 */
CAMERA_EXPORT bool YUV422toRGB888(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool YUV422toRGB32(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool YUV422toRGB888(const uchar *pData, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool YUV422toRGB32(const uchar *pData, AVPixelFormat format, QSize size, QImage &image);

/**
 * @brief BayertoRGB888
 * @param pData
 * @param format AV_PIX_FMT_BAYER_BGGR8,
 *               AV_PIX_FMT_BAYER_RGGB8,
 *               AV_PIX_FMT_BAYER_GBRG8,
 *               AV_PIX_FMT_BAYER_GRBG8
 * @param size
 * @param image
 * @return
 */
CAMERA_EXPORT bool Bayer8toRGB888(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool Bayer8toRGB32(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool Bayer8toRGB888(const uchar *pData, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool Bayer8toRGB32(const uchar *pData, AVPixelFormat format, QSize size, QImage &image);
/**
 * @brief Bayer16toRGB888
 * @param pData
 * @param format AV_PIX_FMT_BAYER_BGGR16LE
 *               AV_PIX_FMT_BAYER_BGGR16BE
 *               AV_PIX_FMT_BAYER_RGGB16LE
 *               AV_PIX_FMT_BAYER_RGGB16BE
 *               AV_PIX_FMT_BAYER_GBRG16LE
 *               AV_PIX_FMT_BAYER_GBRG16BE
 *               AV_PIX_FMT_BAYER_GRBG16LE
 *               AV_PIX_FMT_BAYER_GRBG16BE
 * @param size
 * @param image
 * @return
 */
CAMERA_EXPORT bool Bayer16toRGB888(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool Bayer16toRGB32(const uchar *pData, int stride, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool Bayer16toRGB888(const uchar *pData, AVPixelFormat format, QSize size, QImage &image);
CAMERA_EXPORT bool Bayer16toRGB32(const uchar *pData, AVPixelFormat format, QSize size, QImage &image);
}
#endif // PIXELFORMATCOVERT_H
